********************************************************************************
* Panel A: DA's only
********************************************************************************

use dataset_representation, clear

keep if official_g == "DA"

replace population = log(population)
replace popdensity = log(popdensity)
replace nattorneys = log(nattorneys / population)

label variable population "Log population"
label variable popdensity "Log pop. density"
label variable pctcollege "Pct. college"
label variable pctnonwhite "Pct. nonwhite"
label variable nattorneys "Log attorneys per capita"
label variable property "Property crime per capita"
label variable violent "Violent crime per capita"
label variable vot_ "Voter liberalism"

local X population popdensity pctcollege pctnonwhite nattorneys ///
	proper viol vot_

eststo clear

foreach x in `X' {
	eststo: reg cong `x', cl(district)
}

eststo: reg cong `X', cl(district)

#delimit;

esttab
	using "_output/table 3a.tex"
	,
		label
		replace
		booktabs
		cells(b(fmt(3) star) se(par))
		collabels(none)
		nomtitles
		gap
		width(\linewidth)
		align(c)
		stats(N N_clust, 
			label("Observations" "Clusters")
			fmt(%20.0fc)
		)
		;
		
#delimit cr

********************************************************************************
* Panel B: Compared to other offices
********************************************************************************

use dataset_representation, clear

gen vot2 = vot*vot
label variable vot_ "Voter liberalism"
label variable vot2 "Liberalism squared"

eststo clear
eststo, title("District attorneys"): bs, reps(1000): reg cong vot_ vot2 if ///
	official == "DA", cluster(district_official)
eststo, title("Local officials"): bs, reps(1000): reg cong vot_ vot2 if ///
	official_group == "Local", cluster(district_official)
eststo, title("State legislators"): bs, reps(1000): reg cong vot_ vot2 if ///
	official_group == "State legislator", cluster(district_official)
eststo, title("US House members"): bs, reps(1000): reg cong vot_ vot2 if ///
	official_group == "US House member", cluster(district_official)

#delimit;

esttab
	using "_output/table 3b.tex"
	,
		label
		replace
		booktabs
		cells(b(fmt(3) star) se(par))
		collabels(none)
		mtitles
		gap
		width(0.8\linewidth)
		align(c)
		stats(N N_clust, 
			label("Observations" "Clusters")
			fmt(%20.0fc)
		)
		;
		
#delimit cr

********************************************************************************
* End
********************************************************************************
